package com.xu.t1.middleware.online;

import com.xu.t1.middleware.redis.ExpiredKeyHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 实现了 ExpiredKeyHandler 接口
 * 处理在线用户相关的过期 Key
 *
 * @author xu
 *
 */

@Component("online")
public class OnlineKeyHandler implements ExpiredKeyHandler {

    @Autowired
    private OnlineUserManager onlineUserManager;

    @Override
    public void handle(String[] parts) {
        if (parts.length == 3) {
            String online = parts[0];
            String clientId = parts[1];
            String serverId = parts[2];
            onlineUserManager.removeUserOnline(online, clientId, serverId);
        } else {
            System.err.println("online key 格式不正确: " + String.join(":", parts));
        }
    }
}